home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / PROPSHT.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  16KB  |  503 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.26  $
  6. //
  7. // Definition of classes encapsulating PropertySheets and PropertyPages
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_PROPSHT_H)
  10. #define OWL_PROPSHT_H
  11.  
  12. #if !defined(OWL_DEFS_H)
  13. # include <owl/defs.h>
  14. #endif
  15. #if !defined(OWL_DIALOG_H)
  16. # include <owl/dialog.h>
  17. #endif
  18. #if !defined(OWL_COMMCTRL_H)
  19. # include <owl/commctrl.h>
  20. #endif
  21.  
  22. #if defined(BI_NAMESPACE)
  23. namespace OWL {
  24. #endif
  25.  
  26. // Documented but missing from system headers!
  27. //
  28. #if !defined(PSH_MULTILINETABS)
  29. # define PSH_MULTILINETABS 0x0010
  30. #endif
  31.  
  32. // Generic definitions/compiler options (eg. alignment) preceeding the 
  33. // definition of classes
  34. #include <services/preclass.h>
  35.  
  36. class _OWLCLASS TIcon;
  37. class _OWLCLASS TPropertySheet;
  38. class _OWLCLASS TPropertyPage;
  39. class _OWLCLASS TTabControl;
  40. class _OWLCLASS TTabKeyDown;
  41.  
  42. //
  43. // Prototypes of callbacks used to iterate through PropertyPages
  44. //
  45. typedef void (*TActionPageFunc)(TPropertyPage* pPage, void* param);
  46. typedef bool (*TCondPageFunc)(TPropertyPage* pPage, void* param);
  47.  
  48. //----------------------------------------------------------------------------
  49. // TPropertyPage
  50. //----------------------------------------------------------------------------
  51.  
  52. //
  53. // class TPropertyPage
  54. // ~~~~~ ~~~~~~~~~~~~~
  55. // The 'TPropertyPage' object represents a dialog box found within a property
  56. // sheet. Each 'page' contains controls for setting a group of related
  57. // properties. Each page has a tab that the user can select to bring the page
  58. // to the foreground of the property sheet.
  59. //
  60. class _OWLCLASS TPropertyPage: public TDialog {
  61.   public:
  62.     TPropertyPage(TPropertySheet* parent, TResId resId,
  63.                   const char far* title = 0,
  64.                   TResId iconRes = 0,
  65.                   TModule* module = 0);
  66.    ~TPropertyPage();
  67.  
  68.     // Set attributes of the page
  69.     //
  70.     void            SetIcon(const TIcon&);
  71.     void            SetIcon(TResId iconResId);
  72.     void            SetTitle(const char far*);
  73.     void            SetTitle(int txtResId);
  74.     void            SetFlags(uint32 flags);
  75.  
  76.     // Retrieve Sheet object [i.e. Parent of page]
  77.     //
  78.     TPropertySheet* GetSheet() const;
  79.  
  80.     // Operator to return HPROSHEETPAGE handle
  81.     //
  82.     operator        HPROPSHEETPAGE() const;
  83.  
  84.     // Retrieve information about this page
  85.     //
  86.     void            CopyPageInfo(PROPSHEETPAGE& pgInfo) const;
  87.     PROPSHEETPAGE&  GetPropSheetPage();
  88.  
  89.     // Create/Destroy the HPROPSHEETPAGE handle that uniquely identifies this
  90.     // page.
  91.     //
  92.     HPROPSHEETPAGE  CreatePropertyPage();
  93.     bool            DestroyPropertyPage();
  94.  
  95.     // Override this to process messages within the dialog function
  96.     // Return true if message handled, false if not.
  97.     //
  98.     virtual bool    DialogFunction(uint msg, TParam1 p1, TParam2 p2);
  99.  
  100.     // Overriden to patch PSN_FIRST-PSN_LAST notifications
  101.     //
  102.     virtual TResult EvNotify(uint id, TNotify far& notifyInfo);
  103.  
  104.     // Overriden virtuals of TWindow/TDialog
  105.     //
  106.     bool            Create();
  107.  
  108.     // This is the callback invoked when the a property sheet page is created
  109.     // and destroyed
  110.     //
  111.     static uint CALLBACK OWL_EXPORT16
  112.     PropCallback(HWND hwnd, uint uMsg, LPPROPSHEETPAGE ppsp);
  113.  
  114.     // This is the callback invoked when notifications are sent to the pages
  115.     //
  116.     static int CALLBACK OWL_EXPORT16
  117.     PropDlgProc(HWND hDlg, uint msg, WPARAM wParam, LPARAM lParam);
  118.  
  119.   protected:
  120.  
  121.     // Virtual methods to handle the Sheet notifications. Some of these 
  122.     // methods will most likely be overriden by TPropertyPage-derived classes
  123.     //
  124.     virtual   int   SetActive(TNotify&);    // PSN_SETACTIVE
  125.     virtual   bool  KillActive(TNotify&);   // PSN_KILLACTIVE
  126.     virtual   int   Apply(TNotify&);        // PSN_APPLY
  127.     virtual   void  Reset(TNotify&);        // PSN_RESET
  128.     virtual   void  Help(TNotify&);         // PSN_HELP
  129.     virtual   int   WizBack(TNotify&);      // PSN_WIZBACK
  130.     virtual   int   WizNext(TNotify&);      // PSN_WIZNEXT
  131.     virtual   bool  WizFinish(TNotify&);    // PSN_FINISH
  132.     virtual   bool  QueryCancel(TNotify&);  // PSN_QUERYCANCEL
  133.  
  134.     // Following structure holds information about this dialog when it is
  135.     // inserted into a PropertySheet
  136.     //
  137.     PROPSHEETPAGE   PageInfo;
  138.  
  139.     // Handle of this property page
  140.     //
  141.     HPROPSHEETPAGE  HPropPage;
  142.  
  143. #if !defined(OWL_NATIVECTRL_ALWAYS) && !defined(BI_PLAT_WIN32)
  144.     // Flags if native implementation is used
  145.     //
  146.     bool            UseNative;
  147.  
  148.   public:
  149.     // Get/Set caption
  150.     //
  151.     bool            GetPageCaption(char* txt, int size);
  152.     void            SetPageCaption(char far* caption);
  153.     void            SetUseNative(bool useNative) { UseNative = useNative; }
  154. #endif
  155.  
  156.   private:
  157.     // Hidden to prevent accidental copying or assignment
  158.     //
  159.     TPropertyPage(const TPropertyPage&);
  160.     TPropertyPage& operator =(const TPropertyPage&);
  161.  
  162.     // Initialization shared by constructors
  163.     //
  164.     void Init(TResId resId, const char far* title,
  165.       TResId iconRes, uint32 flags);
  166.  
  167.     // Method that ties the C++ object presenting the page with the underlying
  168.     // 'HWND' handle.
  169.     //
  170.     static void     InitHandle(THandle pageHandle, LPPROPSHEETPAGE pageInfo);
  171.  
  172.     // Iterator callback allowing each page to register its children
  173.     //
  174.     static void     RegisterPageChildObjects(TPropertyPage* page, void*);
  175.  
  176. #if !defined(OWL_NATIVECTRL_ALWAYS) && !defined(BI_PLAT_WIN32)
  177.  
  178.     // The following methods are only valid when ObjectWindows is providing
  179.     // the underlying implementation of PropertySheet/Page. These methods are
  180.     // protected to support derived classes. However, your derived classes
  181.     // should be implemented to rely on these methods only when the Common
  182.     // Control library is unavailable and ObjectWindows is providing the
  183.     // underlying implementation of PropertySheet/PropertyPages.
  184.     //
  185.  
  186.     // Caption of dialog as stored in resource
  187.     //
  188.     TAPointer<char> ResCaption;
  189.  
  190.   public:
  191.     void            SetModified(bool modified);
  192.     bool            IsModified() const;
  193.  
  194.   protected:
  195.     void            SetupWindow();
  196.  
  197.     // Child notifications
  198.     //
  199.     void            CmOk();      // IDOK
  200.     void            CmCancel();  // IDCANCEL
  201.  
  202.  
  203.   private:
  204.     bool            Modified;
  205. #endif
  206.  
  207.     friend          TPropertySheet;
  208.     DECLARE_RESPONSE_TABLE(TPropertyPage);
  209. };
  210.  
  211. //----------------------------------------------------------------------------
  212. // TPropertySheet
  213. //----------------------------------------------------------------------------
  214. class _OWLCLASS TPshNotify : public PSHNOTIFY {
  215.   public:
  216.     TPshNotify(HWND hwnd, uint id, uint code, LPARAM lp);
  217.     operator  NMHDR&() { return hdr; }
  218. };
  219.  
  220. //
  221. // class TPropertySheet
  222. // ~~~~~ ~~~~~~~~~~~~~~
  223. // TPropertySheet encapsulates a window which contains one or more overlapping
  224. // child windows knowns as property pages. The sheet provides a container
  225. // which display pages allowing the user to view and edit related properties
  226. // grouped in individual pages.
  227. //
  228. class _OWLCLASS TPropertySheet : public TWindow {
  229.   public:
  230.     TPropertySheet(TWindow* parent, const char far* title,
  231.                    uint startPage = 0,
  232.                    bool isWizard = false,
  233.                    uint32 flags = PSH_DEFAULT,
  234.                    TModule* module = 0);
  235.    ~TPropertySheet();
  236.  
  237.     // Override virtual functions defined by class TWindow
  238.     //
  239.     void            SetCaption(const char far* title);
  240.     int             Execute();
  241.     bool            Create();
  242.     int             Run(bool modal);
  243.  
  244.     // Manipulate (add, remove, select) pages of the property sheet
  245.     //
  246.     void            AddPage(TPropertyPage&);
  247.     bool            SelectPage(TPropertyPage&);
  248.     bool            SelectPage(int pgIndex);
  249.     bool            SelectPage(TResId pgRes);
  250.     void            RemovePage(TPropertyPage&);
  251.     void            RemovePage(int pgIndex);
  252.     int             GetPageCount() const;
  253.  
  254.     // Inform sheet of changes in state of page
  255.     //
  256.     void            PageChanged(const TPropertyPage&);
  257.     void            PageUnchanged(TPropertyPage&);
  258.  
  259.     // Have sheet simulate user actions
  260.     //
  261.     void            PressButton(int button);
  262.     bool            Apply();
  263.  
  264.     // Query the pages of the sheet
  265.     //
  266.     int             QuerySiblings(TParam1, TParam2);
  267.  
  268.     // Inform sheet of special requirements
  269.     //
  270.     void            RebootSystem();
  271.     void            RestartWindows();
  272.  
  273.     // Update sheet attributes: title, buttons, ...
  274.     //
  275.     void            SetTitle(const char far* text,
  276.                              uint32 style = PSH_PROPTITLE);
  277.     void            SetFinishText(const char far* text);
  278.     void            SetWizButtons(uint32 flags);
  279.     void            CancelToClose();
  280.  
  281.     // Retrieve handle to underlying tab control or current page
  282.     //
  283.     HWND            GetTabControl() const;
  284.     HWND            GetCurrentPage() const;
  285.  
  286.     // Allow processing of dialog messages
  287.     //
  288.     bool            IsDialogMessage(MSG far& msg);
  289.  
  290.     // Retrieve the structure describing the sheet
  291.     //
  292.     PROPSHEETHEADER& GetPropSheetHeader();
  293.  
  294.     // Helper routines to query/iterate about/through pages
  295.     //
  296.     void            ForEachPage(TActionPageFunc action, void* paramList = 0);
  297.     TPropertyPage*  FirstPageThat(TCondPageFunc cond, void* paramList = 0);
  298.  
  299.     // Tell OWL to subclass the sheet after it's created
  300.     //
  301.     void            EnableSubclass(bool subclass);
  302.  
  303.   protected:
  304.     bool            SubClassSheet;  // Should we subclass the sheet (OS only)
  305.  
  306.     // Holds information necessary to create the property sheet
  307.     //
  308.     PROPSHEETHEADER HeaderInfo;
  309.  
  310.     // Flags if sheet is a wizard
  311.     //
  312.     bool            IsWizard;
  313.  
  314.     bool            PreProcessMsg(MSG& msg);
  315.  
  316.   private:
  317.     // Hidden to prevent accidental copying or assignment
  318.     //
  319.     TPropertySheet(const TPropertySheet&);
  320.     TPropertySheet& operator =(const TPropertySheet&);
  321.  
  322.     // Helper routine to retrieve handle of pages
  323.     //
  324.     bool            GetPageHandles();
  325.  
  326.     // Method that ties the C++ object presenting the sheet
  327.     // with the underlying 'HWND' handle.
  328.     //
  329.     void            InitHandle(THandle sheetHandle);
  330.  
  331. #if !defined(OWL_NATIVECTRL_ALWAYS) && !defined(BI_PLAT_WIN32)
  332.  
  333.     // The following methods are only valid when ObjectWindows is providing
  334.     // the underlying implementation of PropertySheet/Page. These methods are
  335.     // provided to support derived classes. However, your derived classes
  336.     // should be implemented to rely on these methods only when the Common
  337.     // Control library is unavailable and ObjectWindows is providing the
  338.     // underlying implementation of PropertySheet/PropertyPages.
  339.     //
  340.  
  341.   public:
  342.     void            SetUseNative(bool useNative) { UseNative = useNative; }
  343.  
  344.   protected:
  345.     // Are we emulating or using OS support
  346.     //
  347.     bool            UseNative;      
  348.  
  349.     // Override TWindow virtuals
  350.     //
  351.     void            SetupWindow();
  352.     char far*       GetClassName();
  353.     void            GetWindowClass(WNDCLASS& wndClass);
  354.     void            EvClose();
  355.  
  356.     // Helper routines to ask for info. about pages of sheet
  357.     //
  358.     TPropertyPage*  PageAtIndex(int index) const;
  359.     int             IndexOfPage(const TPropertyPage* page) const;
  360.     TPropertyPage*  GetActivePage() const;
  361.     bool            SetActivePage(int index);
  362.     int             TabIndexOfPage(const TPropertyPage* page) const;
  363.     TPropertyPage*  PageAtTabIndex(int index) const;
  364.  
  365.     // Helper routines to create, position, size, sync. tab, pages
  366.     // and the buttons of the property sheet. 
  367.     //
  368.     void            SyncTabAndPages();
  369.     virtual void    UpdateTabAndSheetSize(const TRect& pageRect);
  370.     virtual void    PositionPage(TPropertyPage* page);
  371.     virtual void    ComputeMarginAndButton();
  372.     virtual bool    CreateButtons();
  373.     HWND            CreateButton(int id, const char* caption);
  374.     virtual bool    UpdateButtons();
  375.  
  376.     // Variables
  377.     //
  378.     TTabControl*    Tab;                // Pointer to tab control
  379.     int             ActiveIndex;        // Index of active page
  380.     TRect           PageRect;           // Area occupied to page
  381.     HWND            FocusHwnd;          // Handle of focus window
  382.     TSize           ButtonSize;         // Width/Height of buttons
  383.     int             Margin;             // Tab/Dialog & Button/Button margin
  384.     bool            ApplyEnabled;       // Apply button enabled;
  385.     TFont*          Font;               // Pointer to font object
  386.  
  387.     // Event Handlers
  388.     //
  389.     void            EvSize(uint sizeType, TSize& size);
  390.     void            EvActivate(uint active, bool minimized, THandle other);
  391.     void            EvSetFocus(THandle hWndLostFocus);
  392.     HFONT           EvGetFont();
  393.  
  394.     void            TabSelChange(TNotify far& nmHdr);
  395.     bool            TabSelChanging(TNotify far& nmHdr);
  396.     void            TabKeyDown(TTabKeyDown far& kdNot);
  397.  
  398.     void            ButtonClicked(uint id);
  399.  
  400.     DECLARE_RESPONSE_TABLE(TPropertySheet);
  401. #endif
  402.  
  403.     friend          TPropertyPage;
  404. };
  405.  
  406. // Generic definitions/compiler options (eg. alignment) following the 
  407. // definition of classes
  408. #include <services/posclass.h>
  409.  
  410. #if defined(BI_NAMESPACE)
  411. } // namespace OWL
  412. #endif
  413.  
  414. //----------------------------------------------------------------------------
  415. // Inline implementations
  416. //
  417. inline
  418. TPshNotify::TPshNotify(HWND hwnd, uint id, uint code, LPARAM lp)
  419. {
  420.   hdr.hwndFrom = hwnd;
  421.   hdr.idFrom = id;
  422.   hdr.code = code;
  423.   lParam = lp;
  424. }
  425.  
  426. //
  427. // Returns the HPROPSHEETPAGE handle representing an unlying PropertyPage.
  428. // NOTE: This method is only functional when the Common Control library
  429. //       provides the underlying implementation of PropertyPages.
  430. //
  431. // NOTE: The 'CreatePropertyPage' method also returns the HPROPSHEETPAGE.
  432. //       However, it will attempt to create the page if the latter had not been
  433. //       created beforehand. The HPROPSHEETPAGE operator simply returns the
  434. //       page handle without attempting to create the page.
  435. //
  436. inline TPropertyPage::operator HPROPSHEETPAGE() const
  437. {
  438.   PRECONDITION(HPropPage);
  439.   return HPropPage;
  440. }
  441.  
  442. //
  443. // Return structure which describes the characteristics/attributes of page.
  444. //
  445. inline PROPSHEETPAGE&  
  446. TPropertyPage::GetPropSheetPage()
  447. {
  448.   return PageInfo;  
  449. }
  450.  
  451. //
  452. // Return pointer to parent/sheet object
  453. //
  454. inline TPropertySheet*
  455. TPropertyPage::GetSheet() const
  456. {
  457.   CHECK(GetParentO());
  458.   CHECK(TYPESAFE_DOWNCAST(GetParentO(), TPropertySheet));
  459.   return TYPESAFE_DOWNCAST(GetParentO(), TPropertySheet);
  460. }
  461.  
  462. #if !defined(OWL_NATIVECTRL_ALWAYS) && !defined(BI_PLAT_WIN32)
  463. //
  464. //
  465. //
  466. inline void            
  467. TPropertyPage::SetModified(bool modified) 
  468. {
  469.   Modified = modified;
  470. }
  471.  
  472. //
  473. //
  474. //
  475. inline bool            
  476. TPropertyPage::IsModified() const
  477. {
  478.   return Modified;
  479. }
  480. #endif
  481.  
  482. // Return structure which describes the characteristics/attributes of sheet.
  483. //
  484. inline PROPSHEETHEADER& 
  485. TPropertySheet::GetPropSheetHeader() 
  486. {
  487.   return HeaderInfo;  
  488. }
  489.  
  490. //
  491. //
  492. inline void
  493. TPropertySheet::EnableSubclass(bool subclass)
  494. {
  495.   // Method must be invoked before the sheet is created
  496.   //
  497.   PRECONDITION(GetHandle() == 0);
  498.   SubClassSheet = subclass;
  499. }
  500.  
  501.  
  502. #endif  // OWL_PROPSHT_H
  503.